package config

import (
	"fmt"
	"gopkg.in/gcfg.v1"
	"log"
	"os"
	"runtime"
)

type App struct {
	Port int `json:"port"`
}

type Config struct {
	Clickhouse struct {
		Db       string
		Host     string
		Port     int
		User     string
		Password string
		Debug    bool
	} `cfg:"mysql"`
	Redis struct {
		Db       int
		Address  string
		Password string
	} `cfg:"redis"`
	Service struct {
		Port int
		Mode string
	} `cfg:"service"`
}

var GlobalConfig Config

func init() {
	var fileName = "config/config.ini"
	if runtime.GOOS == "windows" {
		fileName = "config/default.ini"
	}
	iniBytes, err := os.ReadFile(fileName)
	if err != nil {
		log.Fatalln(fileName + " file no exist !!!")
	}
	err = gcfg.ReadStringInto(&GlobalConfig, string(iniBytes))
	if err != nil {
		fmt.Println(err)
		return
	}
}

var TablePrefix = "bd_"
